# -*- coding: utf-8 -*-
"""
检查审批配置
"""

import sys
from pathlib import Path

# 添加项目根目录到路径
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))

from src.llm.hiagent_app.utils.api_client import HiAgentAPIClient
import json

def check_approval_config():
    """检查审批配置"""
    client = HiAgentAPIClient()

    print("=" * 80)
    print("[INFO] Checking Approval Configuration")
    print("=" * 80)

    try:
        # 获取审批配置
        result = client.make_request(
            action="GetApprovalConfig",
            body={
                "SupportApproveKinds": ["AppPublish"],
                "Top": {}
            }
        )

        print("\n[Response]:")
        print(json.dumps(result, indent=2, ensure_ascii=False))

        # 解析配置
        if "Response" in result:
            configs = result["Response"].get("configs", [])
        else:
            configs = result.get("configs", [])

        print("\n" + "=" * 80)
        print("[Summary]:")
        print("=" * 80)

        for config in configs:
            kind = config.get("Kind")
            config_type = config.get("Type")
            print(f"\nKind: {kind}")
            print(f"Type: {config_type}")

            if config_type == "Native":
                native_config = config.get("NativeConfig", {})
                print(f"ApproverRole: {native_config.get('ApproverRole')}")
                print(f"CondType: {native_config.get('CondType')}")
            elif config_type == "External":
                external_config = config.get("ExternalConfig", {})
                print(f"EventURL: {external_config.get('EventURL')}")
            elif config_type == "Disabled":
                print("Approval is DISABLED for this kind")

        print("\n" + "=" * 80)

    except Exception as e:
        print(f"\n[ERROR] Failed to check approval config: {str(e)}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    check_approval_config()
